package com.haiyou.dc.thread.test1;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 线程安全：并发容器CopyOnWriteArrayList
 */
public class SynContainerTest {

    public static void main(String[] args) throws InterruptedException {

        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                list.add(Thread.currentThread().getName());
            }).start();
        }
        Thread.sleep(5000);
        System.out.println(list.size());

    }
}
